<?php

require_once './include/common.inc.php';
$page_title = 'jans2en furniture - Products - Product Listing';
$menu_id = 5;
$noproductNote='这个类别内没有产品。';
getMyParam('fid');
getMyParam('categoryid');
getMyParam('settingid');
getMyParam('collectionid');
getMyParam('styleid');
getMyParam('viewall');


$postiondiv='';
$baner_img='';
$positionName = '';

//Modified by Leo 2010-06-28

$sqlWhere = ''; //
$sqlOrderBy = '';//
$sql = '';//ѯSQL
$listPage = 'product_photo_list.php';//Ŀҳ
$vNull = null;
//Viewall 
$parViewAll = '';
if($fid > 0) $parViewAll = '&fid='.$fid.'&viewall=1';
else $parViewAll = '&viewall=1';
$ViewAllUrl = '';

if($styleid >= 0 && $styleid != "")
{
	//$noproductNote='No Style/Period in this category';
	  $noproductNote='在这产品类内没有 "风格/时期"。';
	$page_url = $listPage.'?styleid='.$styleid.'&';
	$ViewAllUrl = $listPage.'?styleid='.$styleid .$parViewAll;
	$sql_style = " AND p.`style_id`= ".$styleid;		
	if($styleid == 0) $sql_style = "AND p.`style_id`>0";
	$sqlWhere = " WHERE c.publish=1 AND c.`id`=pc.`category_id`  AND pc.`product_id`=p.`id`  AND p.`hidden_flag`=0 ".$sql_style." GROUP BY p.`id`";
	$sqlOrderBy = " ORDER BY p.`code` DESC ";
	
	//$category_list =  GetCategoryTable($_style,$listPage.'?styleid=%d',0,$styleid,0,&$vNull);
	$category_list =  GetCategoryTableStyle($_style,$listPage.'?styleid=%d',0,$styleid,0,&$vNull);
	
	$postiondiv = GetPositionLink($_style,$styleid,"style.php","风格/时期","styleid",&$positionName);
		
}
else if($settingid !=""  && $categoryid >= 0)
{
	$noproductNote='这系列没有配套。';
	$page_url = $listPage.'?categoryid='.$categoryid.'&settingid='.$settingid.'&';
	$ViewAllUrl = $listPage.'?categoryid='.$categoryid.'&settingid='.$settingid.$parViewAll;
	$sql_cate = ''; 
	if($categoryid > 10000)
	{
		$sql_cate = "  AND p.`new_flag`=1";	
	}
	else
	{
		$cids = GetCategoryTreeIDS($_categories,$categoryid);
		$sql_cate = " AND c.`id` IN(".$cids.")";	
	}
				
	/*if($settingid == 0 || $settingid == "") $strSettingSql = " AND p.`setting_id` > 0";
	else $strSettingSql = " AND p.`setting_id`= ".$settingid;
	
	$sqlWhere = " WHERE c.publish=1 AND c.`id`=pc.`category_id`  AND pc.`product_id`=p.`id` ".$sql_cate."  AND p.`hidden_flag`=0 ".$strSettingSql." GROUP BY p.`id`";*/
	
/*	if($settingid == 0 || $settingid == "") $strSettingSql = " AND p.`setting_id` > 0";
	else $strSettingSql = "AND ps.`product_id`=p.`id`  AND ps.`setting_id`= ".$settingid;	
	*/
	$strTabls="";
	if($settingid == 0 || $settingid == "")
	{
	 //$strSettingSql = " AND p.`setting_id` > 0";
	 //$strSettingSql =" ";	
	 //$strTabls="";
	 $strTabls=",`product_p_setting` ps ";
	 $strSettingSql = "AND ps.`product_id`=p.`id`  ";
	}
	else
	{
	 $strTabls=",`product_p_setting` ps ";
	 $strSettingSql = "AND ps.`product_id`=p.`id`  AND ps.`setting_id`= ".$settingid;
	 }
	
	$sqlWhere =$strTabls. " WHERE c.publish=1 AND c.`id`=pc.`category_id`  AND pc.`product_id`=p.`id` ".$sql_cate."  AND p.`hidden_flag`=0 ".$strSettingSql." GROUP BY p.`id`";
	
	
	$sqlOrderBy = " ORDER BY p.`code` DESC ";
	
	$toUrl = 'product_photo_list.php?categoryid=%d&settingid=%d';
	
	$arySetting = GetSettingAry();
	$category_list = GetSettingMenu($arySetting,$toUrl,$categoryid,$settingid);
	
	$postiondiv = GetSettingPositionLink($arySetting,$toUrl,$categoryid,$settingid,&$positionName);


}
else if($collectionid >= 0 && $collectionid != "")
{

	$noproductNote='这系列没有收藏品。';
	
	$page_url = $listPage.'?collectionid='.$collectionid .'&';
	$ViewAllUrl = $listPage.'?collectionid='.$collectionid .$parViewAll;
	$sql_collection = " AND p.`collection_id`= ".$collectionid;		
	if($collectionid == 0) $sql_collection = " AND p.`collection_id`>0";
	$sqlWhere = " WHERE c.publish=1 AND c.`id`=pc.`category_id`  AND pc.`product_id`=p.`id`  AND p.`hidden_flag`=0 ".$sql_collection." GROUP BY p.`id`";
	$sqlOrderBy = " ORDER BY p.`code` DESC ";
	
	$category_list =  GetCategoryTable($_collection,$listPage.'?collectionid=%d',0,$collectionid,0,&$vNull);
	
	$postiondiv = GetPositionLink($_collection,$collectionid,"collections.php","收藏品","collectionid",&$positionName);
		
}
else if($categoryid > 10000 && $settingid == "") //New Product
{
	$page_url = $listPage.'?categoryid=' . $categoryid .'&';
	$ViewAllUrl = $listPage.'?categoryid='.$categoryid .$parViewAll;
	$sqlWhere = " WHERE c.publish=1 AND c.`id`=pc.`category_id`  AND pc.`product_id`=p.`id`  AND p.`hidden_flag`=0  AND p.`new_flag`=1 GROUP BY p.`id`";
	$sqlOrderBy = " ORDER BY p.`code` DESC ";
	
	$category_list = GetCategoryTable($_categories,$listPage."?categoryid=%d",0,$categoryid,0,&$vNull);
	
	$postiondiv .='<div class="position" id="position"><a href="index.php">首页</a> &gt; <a href="products.php">产品</a> &gt; <a href="'.$listPage.'?categoryid=10001"> 新产品</a></div>';				

}
else if($categoryid >= 0 && $categoryid <=10000 && $settingid == "")
{
	$page_url = $listPage.'?categoryid=' . $categoryid .'&';
	$ViewAllUrl = $listPage.'?categoryid=' . $categoryid.$parViewAll;
	$cids = GetCategoryTreeIDS($_categories,$categoryid);
	$sqlWhere = " WHERE c.publish=1 AND c.`id` IN(".$cids.") AND c.`id`=pc.`category_id`  AND pc.`product_id`=p.`id`  AND p.`hidden_flag`=0  GROUP BY p.`id`";
	$sqlOrderBy = " ORDER BY p.`code` DESC ";
	
	$category_list = GetCategoryTable($_categories,$listPage."?categoryid=%d",0,$categoryid,0,&$vNull);
	
	$postiondiv = GetProductCatePositionDiv($_categories,$categoryid,&$positionName);
	
	
}

$baner_img = GetBannerImg($positionName);

// *** page code start ***
$sql = "SELECT p.`id` FROM `product` p, `product_category` pc, `category` c".$sqlWhere;
$query = $db->query($sql);
$sql_all_num = $db->num_rows($query);
$query = $db->query($sql);
$sql_all_num = $db->num_rows($query);

$ppp = 12;
getMyParam('page');
$page = empty($page) || !ispage($page) ? 1 : $page;
$start_limit = ($page - 1) * $ppp;
if($start_limit > $sql_all_num) {
	$start_limit = 0;
	$page = 1;
}
$page_show = getPhotoPageStr($sql_all_num, $page, $ppp, $page_url);
// *** page code end ***

$sql_limit = 'LIMIT '.$start_limit.', '.$ppp;
if($viewall!='')
	$sql_limit = '';
	
$sql = "SELECT p.`id`, p.`code`, p.`name`, p.`namezh`, p.`pic`, p.`small_pic`, p.`price_1`, p.`price_2`, p.`price_3`, p.`new_flag` ,p.`info`,p.`infozh` FROM `product` p, `product_category` pc, `category` c".$sqlWhere.$sqlOrderBy.$sql_limit;
$photo_ary = array();
$query = $db->query($sql);
while($rs = $db->fetch_array($query)) {
	$rs['code'] = strtoupper($rs['code']);
	$photo_ary[] = $rs;
}	

//View all link
$PagerString = '&nbsp;&nbsp;&nbsp;&nbsp;<a target="_self" href="'.$ViewAllUrl.'">浏览全部</a>';
if($sql_all_num > 0)
	$PagerString = ' &nbsp;'.$page_show['pagelink'].$PagerString;
	
if($viewall !='') 
{
	$PagerString = '&nbsp; 浏览全部 '.$sql_all_num.' 条记录';	
	$page_show['str'] = '您正在浏览';
	if($positionName != '')
		$page_show['str'] .= '"'.$positionName.'" 的全部记录';
}

//$positionName=AddAiralStyle(&$positionName);

require_once PrintEot('header3');
require_once PrintEot('product_photo_list');
require_once PrintEot('footer');

?>